﻿using AuthCenter.Domain;
using AuthCenter.ErorCode;
using AuthCenter.Infrastructure;
using AuthCenter_API.Read.Applications.Commands.RBAC;
using MediatR;

namespace AuthCenter_API.Read.Applications.CommandHandlers.RBAC
{
    public class RoleNameQueryCommandHandler : IRequestHandler<RoleNameQueryCommand, APIResult<List<RoleModel>>>
    {
        private readonly IBaseRepository<RoleModel> _roleRepository;

        public RoleNameQueryCommandHandler(IBaseRepository<RoleModel> roleRepository)
        {
            _roleRepository = roleRepository;
        }

        public Task<APIResult<List<RoleModel>>> Handle(RoleNameQueryCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<RoleModel>> result = new APIResult<List<RoleModel>>();
            result.Code = APIEnum.QuerySuccess;
            result.Message = APIEnum.QuerySuccess.Desc();
            var m = _roleRepository.GetAll().Where(x=>x.IsDel==0).ToList();
            result.Data = m;
            return Task.FromResult(result);
        }
    }
}
